﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Transactions.Configuration;

namespace YasharEl.Infrastructure.Transactions
{
    public static class TransactionUtilities
    {
        #region Constants

        //default is 10 always 10 minutes
        public static TimeSpan DefaultMaxTimeout = TimeSpan.FromMinutes(10);

        #endregion

        #region Public Helper Methods

        public static TimeSpan GetMaxTransactionTimeout()
        {
            var maxTimeout = DefaultMaxTimeout;
            var systemTransactionsGroup = ConfigurationManager.OpenMachineConfiguration()
                .GetSectionGroup("system.transactions");

            if (systemTransactionsGroup != null)
            {
                var machineSettings = systemTransactionsGroup.Sections.Get("machineSettings") as MachineSettingsSection;

                if (machineSettings != null)
                    maxTimeout = machineSettings.MaxTimeout;
            }

            return maxTimeout;
        }

        #endregion
    }
}
